[contents] [prev] [next] [top] [bottom] (2 out of 3)

Strings as Collections

A string (a String, StringConstant, or Text object) is actually a collection of integers which represent Unicode values corresponding to characters. Therefore, when you use collection methods on strings, you need to use the integer which corresponds to the Unicode value of a character rather than the character itself. For example, methods such as add, append, prepend, deleteOne, and deleteAll must be given an integer as value when they are applied to strings. Conversely, if the return value is an object from a collection, and the collection is a string, that return value will be an integer.

The collection access construct is the shortest way to find the Unicode value for a character. You simply create a string of one character and then access the first (and only) character:

"e"[1]
101

To get the character that an integer represents, you can create an empty string, add the integer to it, and then print it as a string:

function intToString intVal ->
	(
	local str := new String
	append str intVal
	print str
	)
intToString 99
"c"


This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.

Copyright 1996 Apple Computer, Inc. All Rights Reserved.